package com.mall.shopping.services;

import com.mall.shopping.IContentService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.converter.ContentConverter;
import com.mall.shopping.dal.entitys.PanelContent;
import com.mall.shopping.dal.persistence.PanelContentMapper;
import com.mall.shopping.dto.NavListResponse;
import com.mall.shopping.dto.PanelContentDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 创建日期: 2022-01-20-14-11
 * author : XGQ
 * description: IContentService
 */
@Service
public class INavigationServiceImpl implements IContentService {

    @Autowired
    PanelContentMapper panelContentMapper;
    @Autowired
    ContentConverter contentConverter;

    @Override
    public NavListResponse queryNavList() {
        NavListResponse navListResponse = new NavListResponse();
        try {
            List<PanelContent> panelContents = panelContentMapper.selectPanelContentAll();
            List<PanelContentDto> panelContentDtos = contentConverter.panelContents2Dto(panelContents);

            navListResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
            navListResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
            navListResponse.setPannelContentDtos(panelContentDtos);
        } catch (Exception e) {
            e.printStackTrace();
            navListResponse.setCode(ShoppingRetCode.DB_EXCEPTION.getCode());
            navListResponse.setMsg(ShoppingRetCode.DB_EXCEPTION.getMessage());
        }

        return navListResponse;
    }
}
